Sensor Fusion for Kinetis MCUs (ISSDK/KSDK version)
control.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NXP Semiconductor
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /*! \file control.h
32  \brief Defines control sub-system
33 
34  Each sensor fusion application will probably have its own set of functions
35  to control the fusion process and report results. This file defines the
36  programming interface that should be followed in order for the fusion functions
37  to operate correctly out of the box. The actual command interpreter is
38  defined separately in DecodeCommandBytes.c. The output streaming function
39  is defined in output_stream.c. Via these three files, the NXP Sensor Fusion
40  Library provides a default set of functions which are compatible with the
41  Sensor Fusion Toolbox. Use of the toolbox is highly recommended at least
42  during initial development, as it provides many useful debug features.
43  The NXP development team will typically require use of the toolbox as a
44  pre-requisite for providing software support.
45 */
46 
47 // Requires sensor_fusion.h to occur first in the #include stackup
48 #ifndef SENSOR_FUSION_CONTROL_H_
49 #define SENSOR_FUSION_CONTROL_H_
50 
51 /// @name Control Port Function Type Definitions
52 /// The "write" and "stream" commands provide two control functions visible at the main()
53 /// level. These typedefs define the structure of those two calls.
54 ///@{
55 typedef int8_t (writePort_t) (struct ControlSubsystem *pComm, uint8_t buffer[], uint16_t nbytes);
57 ///@}
58 
59 /// \brief he ControlSubsystem encapsulates command and data streaming functions.
60 ///
61 /// The ControlSubsystem encapsulates command and data streaming functions
62 /// for the library. A C++-like typedef structure which includes executable methods
63 /// for the subsystem is defined here.
64 typedef struct ControlSubsystem {
65  quaternion_type DefaultQuaternionPacketType; ///< default quaternion transmitted at power on
66  volatile quaternion_type QuaternionPacketType; ///< quaternion type transmitted over UART
67  volatile uint8_t AngularVelocityPacketOn; ///< flag to enable angular velocity packet
68  volatile uint8_t DebugPacketOn; ///< flag to enable debug packet
69  volatile uint8_t RPCPacketOn; ///< flag to enable roll, pitch, compass packet
70  volatile uint8_t AltPacketOn; ///< flag to enable altitude packet
71  volatile int8_t AccelCalPacketOn; ///< variable used to coordinate accelerometer calibration
72  writePort_t *write; ///< low level function to write a char buffer to the serial stream
73  streamData_t *stream; ///< function to create packets for serial stream
75 
76 int8_t initializeControlPort(ControlSubsystem *pComm); ///< Call this once to initialize structures, ports, etc.
77 
78 // Located in output_stream.c:
79 /// Called once per fusion cycle to stream information required by the NXP Sensor Fusion Toolbox.
80 /// Packet protocols are defined in the NXP Sensor Fusion for Kinetis Product Development Kit User Guide.
82 
83 // Located in DecodeCommandBytes.c:
84 /// This function is responsible for decoding commands sent by the NXP Sensor Fusion Toolbox and setting
85 /// the appropriate flags in the ControlSubsystem data structure.
86 /// Packet protocols are defined in the NXP Sensor Fusion for Kinetis Product Development Kit User Guide.
87 void DecodeCommandBytes(SensorFusionGlobals *sfg, char iCommandBuffer[], uint8 sUART_InputBuffer[], uint16 nbytes);
88 
89 /// Used to initialize the Blue Radios Bluetooth module found on the
90 /// FRDM-FXS-MULT2-B sensor shield from NXP.
91 void BlueRadios_Init(void);
92 
93 /// Utility function used to place data in output buffer about to be transmitted via UART
94 void sBufAppendItem(uint8_t *pDest, uint16_t *pIndex, uint8_t *pSource, uint16_t iBytesToCopy);
95 
96 // externals
97 extern uint8_t sUARTOutputBuffer[256]; ///< main output buffer defined in control.c
98 
99 #endif /* SENSOR_FUSION_CONTROL_H_ */
void( streamData_t)(SensorFusionGlobals *sfg, uint8_t *sUARTOutputBuffer)
Definition: control.h:56
enum quaternion quaternion_type
the quaternion type to be transmitted
void BlueRadios_Init(void)
Used to initialize the Blue Radios Bluetooth module found on the FRDM-FXS-MULT2-B sensor shield from ...
Definition: control.c:132
volatile uint8_t AltPacketOn
flag to enable altitude packet
Definition: control.h:70
The top level fusion structure.
streamData_t * stream
function to create packets for serial stream
Definition: control.h:73
volatile int8_t AccelCalPacketOn
variable used to coordinate accelerometer calibration
Definition: control.h:71
uint8_t uint8
Definition: sensor_fusion.h:58
quaternion_type DefaultQuaternionPacketType
default quaternion transmitted at power on
Definition: control.h:65
int8_t initializeControlPort(ControlSubsystem *pComm)
Call this once to initialize structures, ports, etc.
Definition: control.c:182
void sBufAppendItem(uint8_t *pDest, uint16_t *pIndex, uint8_t *pSource, uint16_t iBytesToCopy)
Utility function used to place data in output buffer about to be transmitted via UART.
Definition: output_stream.c:59
void CreateAndSendPackets(SensorFusionGlobals *sfg, uint8_t *sUARTOutputBuffer)
Called once per fusion cycle to stream information required by the NXP Sensor Fusion Toolbox...
he ControlSubsystem encapsulates command and data streaming functions.
Definition: control.h:64
volatile uint8_t DebugPacketOn
flag to enable debug packet
Definition: control.h:68
int8_t( writePort_t)(struct ControlSubsystem *pComm, uint8_t buffer[], uint16_t nbytes)
Definition: control.h:55
struct ControlSubsystem ControlSubsystem
he ControlSubsystem encapsulates command and data streaming functions.
writePort_t * write
low level function to write a char buffer to the serial stream
Definition: control.h:72
void DecodeCommandBytes(SensorFusionGlobals *sfg, char iCommandBuffer[], uint8 sUART_InputBuffer[], uint16 nbytes)
This function is responsible for decoding commands sent by the NXP Sensor Fusion Toolbox and setting ...
uint16_t uint16
Definition: sensor_fusion.h:59
volatile uint8_t RPCPacketOn
flag to enable roll, pitch, compass packet
Definition: control.h:69
SensorFusionGlobals sfg
This is the primary sensor fusion data structure.
volatile quaternion_type QuaternionPacketType
quaternion type transmitted over UART
Definition: control.h:66
volatile uint8_t AngularVelocityPacketOn
flag to enable angular velocity packet
Definition: control.h:67
uint8_t sUARTOutputBuffer[256]
main output buffer defined in control.c
Definition: control.c:59